home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 21 / Mac Magazin and MacEasy Magazine CD - Issue 21.iso / Wissenschaft & Technik / yorick12vr1-nofpu folder / include / testlp.i < prev    next >
Text File  |  1996-02-23  |  7KB  |  265 lines

  1. /*
  2.    TESTLP.I
  3.    Yorick LAPACK benchmark very similar to the Linpack benchmark.
  4.    Contributed by Steve Langer.
  5.  
  6.    $Id$
  7.  */
  8. /*    Copyright (c) 1995.  The Regents of the University of California.
  9.                     All rights reserved.  */
  10.  
  11. func testlp(void)
  12. /* DOCUMENT testlp
  13.      Run a benchmark of Yorick's LUsolve routine similar to the
  14.      Linpack benchmark.
  15.  */
  16. {
  17.   elapsed= array(0.0, 3);
  18.   old= second(0.0);
  19.  
  20.   /* set the size of the matrix */
  21.   if(is_void(is_a_mac)) {
  22.     n= 100;
  23.   } else {
  24.     val= is_a_mac();
  25.     if(val == 1) {
  26.       /* run small problems on 68K Macs with no FPU */
  27.       n= 25;
  28.       write,"68K Macintosh without FPU";
  29.     } else if(val == 2) {
  30.       /* run mdeium problems on 68K Macs with FPU */
  31.       n= 50;
  32.       write,"68K Macintosh with FPU";
  33.     } else {
  34.       /* run full problem on Power Macs */
  35.       n= 100;
  36.       write,"Power Macintosh";
  37.     }
  38.   }
  39.   n= min(500, max(20, n));
  40.   write," using size ",n;
  41.   cray= .056;
  42.   ops= (2.0*n^3)/3.0 + 2.0*n^2;
  43.   /* WARNING WARNING!!! will not allocate extra storage,
  44.      AND will not test case where there is extra storage in matrix a */
  45.   msiz= n;
  46.  
  47.   /* allocate arrays */
  48.   a= array(0.0, msiz, msiz);
  49.   aa= array(0.0, msiz, msiz);
  50.   b= array(0.0, msiz);
  51.   bb= array(0.0, msiz);
  52.   x= array(0.0, msiz);
  53.   time= array(0.0, 8, 6);
  54.   lda= msiz;
  55.   norma= 0.0;
  56.  
  57.   /* set the number of passes to make through the solver loop
  58.      so that time can be measured accurately
  59.      */
  60.   ntimes= 50;
  61.  
  62.   /* generate matrix a and rhs b once and for all */
  63.   matgen,aa,lda,n,bb,norma;
  64.  
  65.   /* copy matrix into place and run first test */
  66.   b= bb;
  67.   a= aa;
  68.   t1= second(old);
  69.   b= LUsolve(a,b);
  70.   total= second(old) - t1;
  71.  
  72.   /* compute a residual to verify results. */
  73.  
  74.   x= b;
  75.   a= aa;
  76.   b= -bb;
  77.   dmxpy,n,b,n,lda,x,a;
  78.   resid= max(abs(b));
  79.   normx= max(abs(x));
  80.   eps= epslon(1.0);
  81.   residn= resid/( n*norma*normx*eps );
  82.   write,"  norm. resid      resid           machep",
  83.   "        x(1)          x(n)";
  84.   write,format="%15.8e%15.8e%15.8e%15.8e%15.8e\n", residn,resid,eps,x(1),x(n);
  85.  
  86.   write,format="\n    times are reported for matrices of order %6d\n",n;
  87.  
  88.   time(1,3)= total;
  89.   time(1,4)= ops/(1.0e6*total);
  90.   time(1,5)= 2.0/time(1,4);
  91.   time(1,6)= total/cray;
  92.   write,format=" times for array with leading dimension of%6d\n", lda;
  93.   write,"   dgesv     mflops       unit      ratio";
  94.   write,format="%11.3e%11.3e%11.3e%11.3e\n", time(1,3),time(1,4),
  95.   time(1,5),time(1,6);
  96.  
  97.   b= bb;
  98.   a= aa;
  99.   t1= second(old);
  100.   b= LUsolve(a,b);
  101.   total= second(old) - t1;
  102.   time(2,3)= total;
  103.   time(2,4)= ops/(1.0e6*total);
  104.   time(2,5)= 2.0/time(2,4);
  105.   time(2,6)= total/cray;
  106.  
  107.   b= bb;
  108.   a= aa;
  109.   t1= second(old);
  110.   b= LUsolve(a,b);
  111.   total= second(old) - t1;
  112.   time(3,3)= total;
  113.   time(3,4)= ops/(1.0e6*total);
  114.   time(3,5)= 2.0/time(3,4);
  115.   time(3,6)= total/cray;
  116.  
  117.   tm2= 0;
  118.   t1= second(old);
  119.   for(i= 1; i <= ntimes; i++) {
  120.     tm= second(old);
  121.     b= bb;
  122.     a= aa;
  123.     tm2 += second(old) - tm;
  124.     b= LUsolve(a,b);
  125.   }
  126.   total= (second(old) - t1 - tm2)/ntimes;
  127.   time(4,3)= total;
  128.   time(4,4)= ops/(1.0e6*total);
  129.   time(4,5)= 2.0/time(4,4);
  130.   time(4,6)= total/cray;
  131.  
  132.   write,format="%11.3e%11.3e%11.3e%11.3e\n", time(2,3),time(2,4),
  133.         time(2,5),time(2,6);
  134.   write,format="%11.3e%11.3e%11.3e%11.3e\n", time(3,3),time(3,4),
  135.         time(3,5),time(3,6);
  136.   write,format=" result of %4d passes through solver\n", ntimes;
  137.   write,"   dgesv     mflops       unit      ratio";
  138.   write,format="%11.3e%11.3e%11.3e%11.3e\n", time(4,3),time(4,4),
  139.         time(4,5),time(4,6);
  140. }
  141.  
  142. func second(old)
  143. {
  144.   /* return the total CPU plus system time for this job,
  145.      less the input argument. */
  146.   timer, elapsed;
  147.   return elapsed(1)+elapsed(2)-old;
  148. }
  149.  
  150. func dmxpy (n1, y, n2, ldm, x, m)
  151. {
  152. /*   purpose:
  153.      multiply matrix m times vector x and add the result to vector y.
  154.  
  155.    parameters:
  156.  
  157.      n1 integer, number of elements in vector y, and number of rows in
  158.          matrix m
  159.  
  160.      y double precision(n1), vector of length n1 to which is added
  161.          the product m*x
  162.  
  163.      n2 integer, number of elements in vector x, and number of columns
  164.          in matrix m
  165.  
  166.      ldm integer, leading dimension of array m
  167.  
  168.      x double precision(n2), vector of length n2
  169.  
  170.      m double precision(ldm,n2), matrix of n1 rows and n2 columns
  171.  
  172.  ----------------------------------------------------------------------*/
  173.   /*   cleanup odd vector */
  174.   j= n2%2;
  175.   if (j >= 1) {
  176.     y(1:n1)+= x(j)*m(1:n1,j);
  177.   }
  178.   /*   cleanup odd group of two vectors */
  179.   j= n2%4;
  180.   if (j >= 2) {
  181.     y(1:n1)+= x(j-1)*m(1:n1,j-1) + x(j)*m(1:n1,j);
  182.   }
  183.   /*   cleanup odd group of four vectors */
  184.   j= n2%8;
  185.   if (j >= 4) {
  186.     y(1:n1)+= x(j-3)*m(1:n1,j-3) + x(j-2)*m(1:n1,j-2) +
  187.               x(j-1)*m(1:n1,j-1) + x(j)*m(1:n1,j);
  188.   }
  189.   /*   cleanup odd group of eight vectors */
  190.   j= n2%16;
  191.   if (j >= 8) {
  192.     y(1:n1)+= x(j-7)*m(1:n1,j-7) + x(j-6)*m(1:n1,j-6) +
  193.               x(j-5)*m(1:n1,j-5) + x(j-4)*m(1:n1,j-4) +
  194.               x(j-3)*m(1:n1,j-3) + x(j-2)*m(1:n1,j-2) +
  195.               x(j-1)*m(1:n1,j-1) + x(j)  *m(1:n1,j);
  196.   }
  197.   /*   main loop - groups of sixteen vectors */
  198.   jmin= j+16;
  199.   for(j=jmin; j<=n2; j+=16) {
  200.     y(1:n1)+= x(j-15)*m(i,j-15) + x(j-14)*m(1:n1,j-14) +
  201.               x(j-13)*m(1:n1,j-13) + x(j-12)*m(1:n1,j-12) +
  202.               x(j-11)*m(1:n1,j-11) + x(j-10)*m(1:n1,j-10) +
  203.               x(j- 9)*m(1:n1,j- 9) + x(j- 8)*m(1:n1,j- 8) +
  204.               x(j- 7)*m(1:n1,j- 7) + x(j- 6)*m(1:n1,j- 6) +
  205.               x(j- 5)*m(1:n1,j- 5) + x(j- 4)*m(1:n1,j- 4) +
  206.               x(j- 3)*m(1:n1,j- 3) + x(j- 2)*m(1:n1,j- 2) +
  207.               x(j- 1)*m(1:n1,j- 1) + x(j)   *m(1:n1,j);
  208.   }
  209. }
  210.  
  211. func matgen(a,lda,n,b,&norma)
  212. {
  213.   init= 1325;
  214.   for(j= 1; j <= n; j++) {
  215.     for(i= 1; i <= n; i++) {
  216.       init= 3125*init % 65536;
  217.       a(i,j)= (init - 32768.0)/16384.0;
  218.     }
  219.   }
  220.   norma= max(a(1:n,1:n));
  221.   b(1:n)= a(1:n,sum:1:n);
  222. }
  223.  
  224. func epslon (x)
  225. {
  226. /*
  227.      estimate unit roundoff in quantities of size x.
  228.  
  229.       double precision a,b,c,eps
  230.  
  231.      this program should function properly on all systems
  232.      satisfying the following two assumptions,
  233.         1.  the base used in representing dfloating point
  234.             numbers is not a power of three.
  235.         2.  the quantity  a  in statement 10 is represented to
  236.             the accuracy used in dfloating point variables
  237.             that are stored in memory.
  238.      the statement number 10 and the go to 10 are intended to
  239.      force optimizing compilers to generate code satisfying
  240.      assumption 2.
  241.      under these assumptions, it should be true that,
  242.             a  is not exactly equal to four-thirds,
  243.             b  has a zero for its last bit or digit,
  244.             c  is not exactly equal to one,
  245.             eps  measures the separation of 1.0 from
  246.                  the next larger dfloating point number.
  247.      the developers of eispack would appreciate being informed
  248.      about any systems where these assumptions do not hold.
  249.  
  250.      *****************************************************************
  251.      this routine is one of the auxiliary routines used by eispack iii
  252.      to avoid machine dependencies.
  253.      *****************************************************************
  254.  
  255.      this version dated 4/6/83.
  256. */
  257.   a= 4.0/3.0;
  258.   do {
  259.     b= a - 1.0;
  260.     c= b + b + b;
  261.     eps= abs(c-1.0);
  262.   } while(eps== 0.0) ;
  263.   return eps*abs(x);
  264. }
  265.